<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span id="flowsetname"></span><div class="move_title"></div><?php include "../public/subturn.php";?></div></div>
    <div class="main-container">
        <div class="block-generic">
            <?php include "../public/substt.php";?>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>借阅人</label>
                        <div class="layui-input-block">
                            <input type="text" name="useer" id="useer" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>借阅部门</label>
                        <div class="layui-input-block">
                            <input type="text" name="depter" id="depter" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>预计归还日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="guidt" id="guidt" placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>用途</label>
                        <div class="layui-input-block">
                            <input type="text" name="purpose" id="purpose" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="1">
                    <div class="opt-btn-group">
                        <div><span>借阅档案明细</span></div>
                        <div>
                            <button type="button" onclick="choose_dang()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">从档案库导入</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_add_row">插入行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_row">删除行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_all">删除全部</button>
                        </div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th><text>*</text>档案名称</th>
                            <th>档案编号</th>
                            <th><text>*</text>借阅份数</th>
                            <th>备注</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="list_list"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>

            <?php include '../public/flowqita.php'?>
            <?php include '../public/upinfo.php'?>
        </div>



    </div>
</form>
<script>


    $("#commentForm").validate({
        rules: {
            useer: {required: true},
            depter: {required: true},
            guidt: {required: true},
            purpose: {required: true},
        },
        messages:{
            useer: {required: "请输入"},
            depter: {required: "请输入"},
            guidt: {required: "请选择"},
            purpose: {required: "请输入"},
        }
    });

    function choose_dang(){
        openPage('../public/choose_dang.php?choose_type=checkbox&page=dang_jie','80%','80%')
    }

    function choose_dang_one(obj){
        var domkey = $(obj).parents('tr').index();
        openPage('../public/choose_dang.php?page=dang_jie_one&domkey='+domkey,'80%','80%')
    }

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_flowdata_add_dang_jie}).done(function(res){
            if (res.code === 2000) {
                var data = res.data;
                chu_flow_qian(data);
                $("#useer").val(data.useer);
                $("#depter").val(data.depter);


                var listAddStr = '';
                listAddStr += '<tr>';
                listAddStr += '<td style="width: 45px">1</td>';
                listAddStr += '<td>';
                listAddStr += '<input type="text" onclick="choose_dang_one(this)" dangid="0" readonly placeholder="请选择" class="layui-input name disabled">';
                listAddStr += '</td>';
                listAddStr += '<td><input type="text" readonly class="layui-input number2 disabled"></td>';
                listAddStr += '<td><input type="number" class="layui-input num"></td>';
                listAddStr += '<td><input type="text" class="layui-input explain"></td>';
                listAddStr += '</tr>';
                short_table_opt_func(listAddStr, 1);


                public_upload_file_load('upload_files', res.data.files);
                render_date();
                render_from();
                initParseMoney();
            }
        });


        form.on('submit(add)', function(data){
            data.field.isturn = $(this).attr('key') || 0;
            data.field.flowrelas = get_choose_val('flowrelas');
            data.field.advaners = tan_tags_getvalue("#advaners", 'user');
            data.field.nexter = tan_tags_getvalue("#nexter", 'user');
            if(data.field.isturn > 0){
                var validRes = $("#commentForm").valid();
                if(!validRes){return false;}

            }



            var list = [''];
            try {
                $('#list_list tr').each(function (i) {
                    var dangid = $(this).find('.name').attr('dangid');
                    var num = $(this).find('.num').val();
                    var explain = $(this).find('.explain').val();


                    var index = i + 1;
                    if(data.field.isturn > 0){
                        if(!dangid){
                            throw new Error('第'+index+'行，请选择档案名称');
                        }
                        if(!num || num < 1){
                            throw new Error('第'+index+'行，请输入借阅份数');
                        }
                    }

                    list.push({
                        dangid:dangid,
                        num:num,
                        explain:explain,
                    });
                });
            } catch(e) {
                $(".listerror").find('span').text(e.message);
                $(".listerror").show();
                return false;
            }
            $(".listerror").hide();
            data.field.list = list;



            data = parseMoney(data);
            data.field.files = public_upload_file_value('upload_files');
            public_flow_submit(data.field, ask_flowdata_add_dang_jie, ask_flowdata_edit_dang_jie, $(this).attr('but'));
            return false;
        });

    });





</script>
</body>
</html>
